using UnityEditor;
using UnityEngine;
using System.Text;
using System.IO;

public static class CopyAssetPathContextMenu
{
    [MenuItem("Assets/复制资源路径", false, 19)]
    private static void CopyAssetPath()
    {
        // 获取选中的资源
        var selectedObjects = Selection.objects;
        if (selectedObjects.Length == 0) return;

        // 收集所有有效的资源路径
        var paths = new StringBuilder();
        foreach (var obj in selectedObjects)
        {
            string path = AssetDatabase.GetAssetPath(obj);
            if (!string.IsNullOrEmpty(path))
            {
                paths.AppendLine(path);
            }
        }

        // 复制到剪贴板
        if (paths.Length > 0)
        {
            GUIUtility.systemCopyBuffer = paths.ToString().Trim();
            Debug.Log($"Copied to clipboard: \n{GUIUtility.systemCopyBuffer}");
        }
    }

    [MenuItem("Assets/Copy Asset Path", true, 19)]
    private static bool ValidateCopyAssetPath()
    {
        // 仅当选中项目视图中的资源时启用菜单
        foreach (var obj in Selection.objects)
        {
            string path = AssetDatabase.GetAssetPath(obj);
            if (!string.IsNullOrEmpty(path) && File.Exists(path))
            {
                return true;
            }
        }
        return false;
    }
}